#Boa:Frame:CriarAgendamento_Frame
# -*- coding: cp1252 -*-

import wx
import wx.lib.masked.timectrl
import wx.lib.masked.textctrl
from ControleAgendamento import *
from ControleCliente import *
from ControleServico import *
import datetime

def create(parent):
    return CriarAgendamento_Frame(parent)

[wxID_CRIARAGENDAMENTO_FRAME, wxID_CRIARAGENDAMENTO_FRAMEBUTTON1, 
 wxID_CRIARAGENDAMENTO_FRAMEBUTTON2, wxID_CRIARAGENDAMENTO_FRAMECHOICE1, 
 wxID_CRIARAGENDAMENTO_FRAMEDATEPICKERCTRL1, 
 wxID_CRIARAGENDAMENTO_FRAMELISTBOX1, wxID_CRIARAGENDAMENTO_FRAMELISTBOX2, 
 wxID_CRIARAGENDAMENTO_FRAMESTATICBOX1, 
 wxID_CRIARAGENDAMENTO_FRAMESTATICTEXT1, 
 wxID_CRIARAGENDAMENTO_FRAMESTATICTEXT2, 
 wxID_CRIARAGENDAMENTO_FRAMESTATICTEXT3, 
 wxID_CRIARAGENDAMENTO_FRAMESTATICTEXT4, 
 wxID_CRIARAGENDAMENTO_FRAMESTATICTEXT5, 
 wxID_CRIARAGENDAMENTO_FRAMESTATICTEXT6, 
 wxID_CRIARAGENDAMENTO_FRAMESTATICTEXT7, 
 wxID_CRIARAGENDAMENTO_FRAMESTATICTEXT8, 
 wxID_CRIARAGENDAMENTO_FRAMESTATICTEXT9, wxID_CRIARAGENDAMENTO_FRAMETIMECTRL1, 
] = [wx.NewId() for _init_ctrls in range(18)]

class CriarAgendamento_Frame(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_CRIARAGENDAMENTO_FRAME,
              name=u'CriarAgendamento_Frame', parent=prnt, pos=wx.Point(422,
              166), size=wx.Size(543, 451), style=wx.DEFAULT_FRAME_STYLE,
              title=u'CriarAgendamento_Frame')
        self.SetClientSize(wx.Size(527, 413))
        self.SetBackgroundColour(wx.Colour(255, 255, 255))

        self.staticText1 = wx.StaticText(id=wxID_CRIARAGENDAMENTO_FRAMESTATICTEXT1,
              label=u'Data', name='staticText1', parent=self, pos=wx.Point(48,
              40), size=wx.Size(44, 23), style=0)
        self.staticText1.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD,
              False, u'Tahoma'))

        self.staticText2 = wx.StaticText(id=wxID_CRIARAGENDAMENTO_FRAMESTATICTEXT2,
              label=u'Hor\xe1rio', name='staticText2', parent=self,
              pos=wx.Point(48, 80), size=wx.Size(72, 23), style=0)
        self.staticText2.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD,
              False, u'Tahoma'))

        self.staticText3 = wx.StaticText(id=wxID_CRIARAGENDAMENTO_FRAMESTATICTEXT3,
              label=u'Cliente', name='staticText3', parent=self,
              pos=wx.Point(48, 120), size=wx.Size(67, 23), style=0)
        self.staticText3.SetBackgroundColour(wx.Colour(255, 255, 255))
        self.staticText3.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD,
              False, u'Tahoma'))

        self.staticText4 = wx.StaticText(id=wxID_CRIARAGENDAMENTO_FRAMESTATICTEXT4,
              label=u'Servi\xe7os', name='staticText4', parent=self,
              pos=wx.Point(48, 160), size=wx.Size(80, 23), style=0)
        self.staticText4.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD,
              False, u'Tahoma'))

        self.listBox1 = wx.ListBox(choices=[],
              id=wxID_CRIARAGENDAMENTO_FRAMELISTBOX1, name='listBox1',
              parent=self, pos=wx.Point(144, 168), size=wx.Size(144, 120),
              style=0)
        self.listBox1.Bind(wx.EVT_LISTBOX_DCLICK, self.OnListBox1ListboxDclick,
              id=wxID_CRIARAGENDAMENTO_FRAMELISTBOX1)

        self.listBox2 = wx.ListBox(choices=[],
              id=wxID_CRIARAGENDAMENTO_FRAMELISTBOX2, name='listBox2',
              parent=self, pos=wx.Point(344, 168), size=wx.Size(148, 120),
              style=0)
        self.listBox2.Bind(wx.EVT_LISTBOX_DCLICK, self.OnListBox2ListboxDclick,
              id=wxID_CRIARAGENDAMENTO_FRAMELISTBOX2)

        self.staticText5 = wx.StaticText(id=wxID_CRIARAGENDAMENTO_FRAMESTATICTEXT5,
              label=u'<', name='staticText5', parent=self, pos=wx.Point(304,
              216), size=wx.Size(17, 25), style=0)
        self.staticText5.SetFont(wx.Font(16, wx.SWISS, wx.NORMAL, wx.BOLD,
              False, u'Tahoma'))

        self.staticText6 = wx.StaticText(id=wxID_CRIARAGENDAMENTO_FRAMESTATICTEXT6,
              label=u'Escolhidos', name='staticText6', parent=self,
              pos=wx.Point(144, 152), size=wx.Size(50, 13), style=0)

        self.staticText7 = wx.StaticText(id=wxID_CRIARAGENDAMENTO_FRAMESTATICTEXT7,
              label=u'Disponiveis', name='staticText7', parent=self,
              pos=wx.Point(344, 152), size=wx.Size(54, 13), style=0)

        self.datePickerCtrl1 = wx.DatePickerCtrl(id=wxID_CRIARAGENDAMENTO_FRAMEDATEPICKERCTRL1,
              name='datePickerCtrl1', parent=self, pos=wx.Point(104, 40),
              size=wx.Size(112, 32), style=wx.DP_SHOWCENTURY)
        self.datePickerCtrl1.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.timeCtrl1 = wx.lib.masked.timectrl.TimeCtrl(display_seconds=True,
              fmt24hr=False, id=wxID_CRIARAGENDAMENTO_FRAMETIMECTRL1,
              name='timeCtrl1', oob_color=wx.NamedColour('Yellow'), parent=self,
              pos=wx.Point(128, 80), size=wx.Size(48, 24), style=0,
              useFixedWidthFont=True, value='12:00:00 AM')
        self.timeCtrl1.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Courier New'))
        self.timeCtrl1.SetFormat('24HHMM')

        self.choice1 = wx.Choice(choices=[],
              id=wxID_CRIARAGENDAMENTO_FRAMECHOICE1, name='choice1',
              parent=self, pos=wx.Point(128, 120), size=wx.Size(376, 26),
              style=0)
        self.choice1.SetFont(wx.Font(11, wx.SWISS, wx.NORMAL, wx.NORMAL, False,
              u'Tahoma'))

        self.staticBox1 = wx.StaticBox(id=wxID_CRIARAGENDAMENTO_FRAMESTATICBOX1,
              label=u'Adicionar Agendamento', name='staticBox1', parent=self,
              pos=wx.Point(16, 8), size=wx.Size(496, 296), style=0)
        self.staticBox1.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

        self.button1 = wx.Button(id=wxID_CRIARAGENDAMENTO_FRAMEBUTTON1,
              label=u'Adicionar Agendamento', name='button1', parent=self,
              pos=wx.Point(24, 336), size=wx.Size(144, 48), style=0)
        self.button1.Bind(wx.EVT_BUTTON, self.OnButton1Button,
              id=wxID_CRIARAGENDAMENTO_FRAMEBUTTON1)

        self.button2 = wx.Button(id=wxID_CRIARAGENDAMENTO_FRAMEBUTTON2,
              label=u'Cancelar', name='button2', parent=self, pos=wx.Point(360,
              336), size=wx.Size(144, 48), style=0)
        self.button2.Bind(wx.EVT_BUTTON, self.OnButton2Button,
              id=wxID_CRIARAGENDAMENTO_FRAMEBUTTON2)

        self.staticText8 = wx.StaticText(id=wxID_CRIARAGENDAMENTO_FRAMESTATICTEXT8,
              label=u'ID: ', name='staticText8', parent=self, pos=wx.Point(352,
              48), size=wx.Size(36, 23), style=0)
        self.staticText8.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.BOLD,
              False, u'Tahoma'))

        self.staticText9 = wx.StaticText(id=wxID_CRIARAGENDAMENTO_FRAMESTATICTEXT9,
              label=u'', name='staticText9', parent=self, pos=wx.Point(392, 48),
              size=wx.Size(0, 23), style=0)
        self.staticText9.SetFont(wx.Font(14, wx.SWISS, wx.NORMAL, wx.NORMAL,
              False, u'Tahoma'))

    def __init__(self, parent):
        self._init_ctrls(parent)
        
        ca = ControleAgendamento()
        self.staticText9.SetLabel(ca.GerarNovoID())
        
        cc = ControleCliente()
        cc.verificarArquivo()
        for cliente in cc.getListaDeClientes():
            self.choice1.Append(cliente.GetNomeCompleto())
        
        cs = ControleServico()
        cs.verificarArquivo()
        for servico in cs.getListaDeServicos():
            self.listBox2.Append(servico.GetNome())
        
        
        
    def OnButton2Button(self, event):
        import Frame_Agendamento
        Frame_Agendamento.create(None).Show()
        self.Close()

    def OnListBox2ListboxDclick(self, event):
        pos = self.listBox2.GetSelection()
        nome = self.listBox2.GetString(pos)
        
        self.listBox1.Append(nome)
        self.listBox2.Delete(pos)

    def OnListBox1ListboxDclick(self, event):
        pos = self.listBox1.GetSelection()
        nome = self.listBox1.GetString(pos)
        
        self.listBox2.Append(nome)
        self.listBox1.Delete(pos)

    def OnButton1Button(self, event):
        ca = ControleAgendamento()
        cc = ControleCliente()
        
        AgendamentoID = self.staticText9.GetLabel()
        
        horarioStr = str(self.timeCtrl1.GetValue())
        hora = int(horarioStr[0:2])
        minutos = int(horarioStr[3:5])
        
        dataStr = str(self.datePickerCtrl1.GetValue())
        mes = int(dataStr[0:2])
        dia = int(dataStr[3:5])
        ano = int(dataStr[6:8])+2000
        
        pos = self.choice1.GetCurrentSelection()
        Obj_Cliente = self.choice1.GetString(pos)
        
        servicos = self.listBox1.GetItems()
        
        ca.cadastrarAgendamento(AgendamentoID, hora, minutos, dia, mes, ano, Obj_Cliente, servicos)
        
        m = 'Agendamento Salvo com Sucesso'
        c = 'Agenda'
        
        wx.MessageBox(m,c,wx.OK)
        
        import Frame_Agendamento
        Frame_Agendamento.create(None).Show()
        self.Close()
